package com.softhinker.ke24.unit1;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class ConstellationHelper 
{
	public static enum CONSTELLATION
	{
		Aries,
		Taurus,
		Gemini,
		Cancer,
		Leo,
		Virgo,
		Libra,
		Scorpio,
		Sagittarius,
		Capricorn,
		Aquarius,
		Pisces
	}
	
	private class MonthConstellation
	{
		private CONSTELLATION earlierConstellation;
		public CONSTELLATION getEarlierConstellation()
		{
			return this.earlierConstellation;
		}
		
		private CONSTELLATION laterConstellation;
		public CONSTELLATION getLaterConstellation()
		{
			return this.laterConstellation;
		}

		private int threshold = -1;
		public int getThreshold()
		{
			return this.threshold;
		}
		
		public MonthConstellation(CONSTELLATION earlier, CONSTELLATION later, int threshold)
		{
			this.earlierConstellation = earlier;
			this.laterConstellation = later;
			this.threshold = threshold;
		}
	}
	
	private List<MonthConstellation> monthConstellationList = new ArrayList<MonthConstellation>(12);
	
	{
		MonthConstellation janMC = new MonthConstellation(CONSTELLATION.Capricorn, CONSTELLATION.Aquarius, 19);
		monthConstellationList.add(janMC);
		
		MonthConstellation febMC = new MonthConstellation(CONSTELLATION.Aquarius, CONSTELLATION.Pisces, 18);
		monthConstellationList.add(febMC);
		
		MonthConstellation marMC = new MonthConstellation(CONSTELLATION.Pisces, CONSTELLATION.Aries, 20);
		monthConstellationList.add(marMC);
		
		MonthConstellation aprMC = new MonthConstellation(CONSTELLATION.Aries, CONSTELLATION.Taurus, 19);
		monthConstellationList.add(aprMC);
		
		MonthConstellation mayMC = new MonthConstellation(CONSTELLATION.Taurus, CONSTELLATION.Gemini, 20);
		monthConstellationList.add(mayMC);
		
		MonthConstellation junMC = new MonthConstellation(CONSTELLATION.Gemini, CONSTELLATION.Cancer, 21);
		monthConstellationList.add(junMC);
		
		MonthConstellation julMC = new MonthConstellation(CONSTELLATION.Cancer, CONSTELLATION.Leo, 22);
		monthConstellationList.add(julMC);
		
		MonthConstellation augMC = new MonthConstellation(CONSTELLATION.Leo, CONSTELLATION.Virgo, 22);
		monthConstellationList.add(augMC);
		
		MonthConstellation sepMC = new MonthConstellation(CONSTELLATION.Virgo, CONSTELLATION.Libra, 22);
		monthConstellationList.add(sepMC);
		
		MonthConstellation octMC = new MonthConstellation(CONSTELLATION.Libra, CONSTELLATION.Scorpio, 23);
		monthConstellationList.add(octMC);
		
		MonthConstellation novMC = new MonthConstellation(CONSTELLATION.Scorpio, CONSTELLATION.Sagittarius, 22);
		monthConstellationList.add(novMC);
		
		MonthConstellation decMC = new MonthConstellation(CONSTELLATION.Sagittarius, CONSTELLATION.Capricorn, 21);
		monthConstellationList.add(decMC);
	}
	
	public String getConstellation(Date date)
	{
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int month = calendar.get(Calendar.MONTH);
		System.out.println("Month : " + (month + 1));
		int day = calendar.get(Calendar.DAY_OF_MONTH);
		MonthConstellation mc = monthConstellationList.get(month);
		
		if(day <= mc.getThreshold())
			return mc.getEarlierConstellation().toString();
		return mc.getLaterConstellation().toString();
	}
	
	public static void main(String[] args)
	{
		Date date = new Date();
		ConstellationHelper helper = new ConstellationHelper();
		String cons = helper.getConstellation(date);
		System.out.println("My constellation is : " + cons);
	}
}
